package com.fingard.dsp.bank.directbank.citic01;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillTrans;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.*;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * 中信电票经办
 */
public class CITIC01ElecBillTrans extends CITIC01Base implements IElecBillTrans {
    //日期的转换
    protected String TransDate(String date) {
        String year = date.substring(0, 4);
        String month = date.substring(5, 6);
        String day = date.substring(7, 8);

        return month + "/" + day + "/" + year;
    }

    //yyyymmdd
    public String TransDateFromATS(String ATS) throws Exception {
        /*String[] date = ATS.split("/");
        String year = date[0];
        String month = date[1];
        if (month.length() == 1) {
            month = "0" + month;
        }
        String day = date[2].substring(0, 1);
        if (day.trim().length() == 1) {
            day = "0" + day.trim();
        }
        return year + month + day;*/
        if (StringHelper.hasAnyChar(ATS)) {
            if (ATS.contains("/") && ATS.length() >= 10) {
                return ATS.substring(0, 10).replace("/", "");
            } else if (ATS.contains("-") && ATS.length() >= 10) {
                return ATS.substring(0, 10).replace("-", "");
            } else {
                return Format.Date8Format.format(new Date());
            }
        } else {
            return Format.Date8Format.format(new Date());
        }
    }

    public RetAtsB003BillRespSubmit D_B003_BillResp_Submit(ReqB003BillRespSubmit query) throws Exception {
        return D_B003(query);
    }

    public RetAtsB101BillApplySubmit D_B101_BillResp_Submit(ReqB101BillApplySubmit query) throws Exception {
        return D_B101(query);
    }

    public RetAtsB102BillAccpSubmit D_B102_BillResp_Submit(ReqB102BillAccpSubmit query) throws Exception {
        return D_B102(query);
    }

    public RetAtsB103BillRetSubmit D_B103_BillResp_Submit(ReqB103BillRetSubmit query) throws Exception {
        return D_B103(query);
    }

    public RetAtsB104BillReceSubmit D_B104_BillResp_Submit(ReqB104BillReceSubmit query) throws Exception {
        return D_B104(query);
    }

    public RetAtsB105BillEndoSubmit D_B105_BillResp_Submit(ReqB105BillEndoSubmit query) throws Exception {
        return D_B105(query);
    }

    public RetAtsB107BillPledSubmit D_B107_BillResp_Submit(ReqB107BillPledSubmit query) throws Exception {
        return D_B107(query);
    }

    public RetAtsB108BillPaySubmit D_B108_BillResp_Submit(ReqB108BillPaySubmit query) throws Exception {
        return D_B108(query);
    }

    public RetAtsB109BillGuarSubmit D_B109_BillResp_Submit(ReqB109BillGuarSubmit query) throws Exception {
        return D_B109(query);
    }

    public RetAtsB110BillRecoSubmit D_B110_BillResp_Submit(ReqB110BillRecoSubmit query) throws Exception {
        return D_B110(query);
    }

    public RetAtsB111BillAgreeSubmit D_B111_BillResp_Submit(ReqB111BillAgreeSubmit query) throws Exception {
        return D_B111(query);
    }

    public RetAtsB112BillCancSubmit D_B112_BillResp_Submit(ReqB112BillCancSubmit query) throws Exception {
        return D_B112(query);
    }

    @Override
    public RetAtsB113ProtocolSubmit D_B113_ProtocolResp_Submit(ReqB113ProtocolSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB119BillRelePledSubmit D_B119_BillResp_Submit(ReqB119BillRelePledSubmit query) throws Exception {
        RetAtsB119BillRelePledSubmit retAts = new RetAtsB119BillRelePledSubmit(query.reqHeader);
        retAts.writeStart();
        RetAtsB119BillRelePledSubmitDetail detail = new RetAtsB119BillRelePledSubmitDetail();
        query.readRecord();
       try{
           XmlTextWriter xmlWriter = new XmlTextWriter();
           xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
           xmlWriter.writeStartElement("stream");
           xmlWriter.writeElementString("action","DLZYJCSQ" );
           xmlWriter.writeElementString("userName",bankFront.loginName );
           xmlWriter.writeElementString("clientID", query.detail.reqSeqID);
           xmlWriter.writeElementString("accountNo", query.detail.actNum);
           xmlWriter.writeElementString("billNo", query.detail.billNo);
           xmlWriter.writeElementString("ecdsBatNo", "");// TODO: 2019/8/14
           xmlWriter.writeElementString("memo", query.detail.memo);
           xmlWriter.writeElementString("preFlg","0" );
           xmlWriter.writeElementString("preDate", "");
           xmlWriter.writeEndDocument();
           String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    detail.respCode = "0";
                    detail.respInfo = tmpBkReader.getSimpleText("statusText");
                    detail.payInfoCode = tmpBkReader.getSimpleText("status");
                    detail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSbMsg.toString();
                }
            } else {
                detail.respCode = "-1";
                detail.respInfo = tmpStrRet[1];
            }
        }catch (Exception ex){
           ex.getStackTrace();
           detail.respCode ="-1";
           detail.respInfo =ex.getMessage();
       }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    public RetAtsB106BillDiscSubmit D_B106_BillResp_Submit(ReqB106BillDiscSubmit query) throws Exception {
        return D_B106(query);
    }


    public RetAtsB003BillRespSubmit D_B003(ReqB003BillRespSubmit query) throws Exception {
        RetAtsB003BillRespSubmit Resp = new RetAtsB003BillRespSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB003BillRespSubmitDetail Respdetial = new RetAtsB003BillRespSubmitDetail();
            Respdetial.reqSeqID = query.detail.reqSeqID;

            String reqCode;
            int RespType = Integer.parseInt(query.detail.respType);
            switch (RespType) {
                case 1: //承兑应答
                    reqCode = "DLTSCDQS"; //提示承兑签收
                    break;
                case 2: //收票应答
                    reqCode = "DLTSSPQS"; //提示收票签收
                    break;
                case 3: //背书转让应答
                    reqCode = "DLBSZRQS"; //背书转让签收
                    break;
                case 4: //回购式贴现赎回应答
                    reqCode = "DLTXSHQS"; //贴现赎回签收
                    break;
                case 5: //质押解除应答
                    reqCode = "DLZYJCQS"; //质押解除签收
                    break;
                case 6: //提示付款应答
                    reqCode = "DLTSFKQS"; //提示付款签收
                    break;
                case 7: //保证应答
                    reqCode = "DLBOZHQS"; //保证签收
                    break;
                case 8: //同意清偿应答
                    reqCode = "DLTYQCQS"; //同意清偿签收
                    break;
                case 9: //质押应答
                    reqCode = "DLZHYAQS"; //质押应答
                    break;
                default:
                    Respdetial.respCode = "-1";
                    Respdetial.respInfo = "不支持该应答类型。";
                    Resp.writeDetail(Respdetial);
                    continue;
            }
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBCMAQS"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("reqCode", reqCode));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("bussqNo", query.detail.busiNo));
            String sgnrRes = "";
            tmpElemnt.addChild(new XElement("sgnrRes", sgnrRes));
            int RespFlag = Integer.parseInt(query.detail.respFlag);
            switch (RespFlag) {
                case 1:
                    sgnrRes = "SU00";
                    break;
                case 2:
                    sgnrRes = "SU01";
                    break;
                default:
                    Respdetial.respCode = "-1";
                    Respdetial.respInfo = "应答标记错误";
                    Resp.writeDetail(Respdetial);
                    continue;
            }
            tmpElemnt.addChild(new XElement("sgnrRes", sgnrRes));
            if("1".equals(query.detail.respType)) {
                tmpElemnt.addChild(new XElement("sgnrRate", query.detail.accpCredit));
                tmpElemnt.addChild(new XElement("sgnrAgcy", query.detail.accpGrade));
                tmpElemnt.addChild(new XElement("sgnrDueDate", DateHelper.convertD10toD8(query.detail.accpGradeDue)));
            }else{
                tmpElemnt.addChild(new XElement("sgnrRate", ""));
                tmpElemnt.addChild(new XElement("sgnrAgcy", ""));
                tmpElemnt.addChild(new XElement("sgnrDueDate", ""));
            }
            if (query.detail.respType.equals("6") && query.detail.respFlag.equals("2")) {
                if(StringHelper.isNullOrEmpty(query.detail.unPayCode)){
                    throw new Exception("提示付款拒签时，拒付理由不能为空!");
                }
                if (query.detail.unPayCode.equals("99")) {
                    tmpElemnt.addChild(new XElement("refuseRsnCd", "DC09"));
                    tmpElemnt.addChild(new XElement("refuseRsn", query.detail.unPayCode));
                } else if (Integer.parseInt(query.detail.unPayCode) > 0 && Integer.parseInt(query.detail.unPayCode) <= 9) {
                    int unPayCode = Integer.parseInt(query.detail.unPayCode);
                    tmpElemnt.addChild(new XElement("refuseRsnCd", "DC0" + (unPayCode - 1)));
                    tmpElemnt.addChild(new XElement("refuseRsn", ""));
                } else {
                    Respdetial.respCode = "-1";
                    Respdetial.respInfo = "拒付理由代码错误";
                    Resp.writeDetail(Respdetial);
                    continue;
                }
            }else{
                tmpElemnt.addChild(new XElement("refuseRsnCd", ""));
                tmpElemnt.addChild(new XElement("refuseRsn", ""));
            }

            tmpElemnt.addChild(new XElement("protocolNo", query.detail.protocolNo));
            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            tmpElemnt.addChild(new XElement("preDate", ""));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    Respdetial.respCode = "0";
                    Respdetial.respInfo = tmpBkReader.getSimpleText("statusText");
                    Respdetial.payInfoCode = tmpBkReader.getSimpleText("status");
                    Respdetial.transState = tmpBkReader.getSimpleText("status");
                } else {
                    Respdetial.respCode = "-1";
                    Respdetial.respInfo = tmpSbMsg.toString();
                }

            } else {
                Respdetial.respCode = "-1";
                Respdetial.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(Respdetial);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB101BillApplySubmit D_B101(ReqB101BillApplySubmit query) throws Exception {
        RetAtsB101BillApplySubmit Resp = new RetAtsB101BillApplySubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB101BillApplySubmitDetail respDetail = new RetAtsB101BillApplySubmitDetail();
            String action;
            if (query.detail.autoPromptAccept.equals("0") && query.detail.autoPromptReceipt.equals("0")) {
                action = "DLBILREG";
            } else if (query.detail.autoPromptAccept.equals("1") && query.detail.autoPromptReceipt.equals("0")) {
                action = "DLBLREG2";
            } else if (query.detail.autoPromptReceipt.equals("1")) {
                action = "DLBLREG3";
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = "获取请求代码错误";
                Resp.writeDetail(respDetail);
                continue;
            }
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", action));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.reqHeader.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.drawAct));
            tmpElemnt.addChild(new XElement("drwrRate", query.detail.creditLv));
            tmpElemnt.addChild(new XElement("drwrAgcy", query.detail.gradeAgent));
            if (!StringHelper.isNullOrEmpty(query.detail.gradeDueDate)) {
                tmpElemnt.addChild(new XElement("rateDueDate", TransDateFromATS(query.detail.gradeDueDate)));
            }
            int BillType = Integer.parseInt(query.detail.billType);
            switch (BillType) {
                case 1:
                    tmpElemnt.addChild(new XElement("billType", "AC01"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("billType", "AC02"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "票据类型错误";
                    Resp.writeDetail(respDetail);
                    continue;
            }
            tmpElemnt.addChild(new XElement("issDate", TransDateFromATS(query.detail.issDate)));
            tmpElemnt.addChild(new XElement("dueDate", TransDateFromATS(query.detail.dueDate)));
            double AmtDown = Double.valueOf(query.detail.billAmt);
            tmpElemnt.addChild(new XElement("tranAmt", String.format("%.2f", AmtDown)));
            int TransFlag = Integer.parseInt(query.detail.transFlag);
            switch (TransFlag) {
                case 1:
                    tmpElemnt.addChild(new XElement("endorseMk", "EM00"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("endorseMk", "EM01"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "背书转让标志错误";
                    Resp.writeDetail(respDetail);
                    continue;
            }
            tmpElemnt.addChild(new XElement("pyeeName", query.detail.payeeName));
            tmpElemnt.addChild(new XElement("pyeeAccNo", query.detail.payeeAct));
            tmpElemnt.addChild(new XElement("pyeeBnm", query.detail.payeeBnkCode));
            tmpElemnt.addChild(new XElement("accpName", query.detail.accpName));

            if (query.detail.accpSameBnk.equals("1") && query.detail.billType.equals("1")) {
                tmpElemnt.addChild(new XElement("accpAccNo", "0"));
            } else {
                tmpElemnt.addChild(new XElement("accpAccNo", query.detail.accpAct));
            }

            tmpElemnt.addChild(new XElement("accpBnm", query.detail.accpBnkCode));

            if (query.detail.billType.equals("1")) {
                int AccpSameBnk = Integer.parseInt(query.detail.accpSameBnk);
                switch (AccpSameBnk) {
                    case 1:
                        tmpElemnt.addChild(new XElement("accpIsCitic", "0"));
                        break;
                    case 2:
                        tmpElemnt.addChild(new XElement("accpIsCitic", "1"));
                        break;
                    default:
                        respDetail.respCode = "-1";
                        respDetail.respInfo = "承兑人是否为中信银行标志错误";
                        continue;

                }
            } else if (query.detail.billType.equals("2")) {
                tmpElemnt.addChild(new XElement("accpIsCitic", "1"));
            }
            tmpElemnt.addChild(new XElement("contract", query.detail.contractNo));
            tmpElemnt.addChild(new XElement("invoiceNo", query.detail.invoiceNo));
            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));

            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB102BillAccpSubmit D_B102(ReqB102BillAccpSubmit query) throws Exception {
        RetAtsB102BillAccpSubmit Resp = new RetAtsB102BillAccpSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB102BillAccpSubmitDetail respDetail = new RetAtsB102BillAccpSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLTSCDSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("contractNo", query.detail.contractNo));
            tmpElemnt.addChild(new XElement("invoiceNo", query.detail.invoiceNo));
            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB103BillRetSubmit D_B103(ReqB103BillRetSubmit query) throws Exception {
        RetAtsB103BillRetSubmit Resp = new RetAtsB103BillRetSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB103BillRetSubmitDetail respDetail = new RetAtsB103BillRetSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLWYTHSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB104BillReceSubmit D_B104(ReqB104BillReceSubmit query) throws Exception {
        RetAtsB104BillReceSubmit Resp = new RetAtsB104BillReceSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB104BillReceSubmitDetail respDetail = new RetAtsB104BillReceSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLTSSPSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB105BillEndoSubmit D_B105(ReqB105BillEndoSubmit query) throws Exception {
        RetAtsB105BillEndoSubmit Resp = new RetAtsB105BillEndoSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB105BillEndoSubmitDetail respDetail = new RetAtsB105BillEndoSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBSZRSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            tmpElemnt.addChild(new XElement("endorserName", query.detail.receName));
            tmpElemnt.addChild(new XElement("endorserAccNo", query.detail.receAct));
            tmpElemnt.addChild(new XElement("endorserBnm", query.detail.receBnkCode));

            int TransFlag = Integer.parseInt(query.detail.transFlag);
            switch (TransFlag) {
                case 1:
                    tmpElemnt.addChild(new XElement("endorseMk", "EM00"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("endorseMk", "EM01"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "转让标志错误";
                    Resp.writeDetail(respDetail);
                    continue;
            }

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB107BillPledSubmit D_B107(ReqB107BillPledSubmit query) throws Exception {
        RetAtsB107BillPledSubmit Resp = new RetAtsB107BillPledSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB107BillPledSubmitDetail respDetail = new RetAtsB107BillPledSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLZHYASQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            tmpElemnt.addChild(new XElement("cobkName", query.detail.receName));
            tmpElemnt.addChild(new XElement("cobkAccNo", query.detail.receAct));
            tmpElemnt.addChild(new XElement("cobkBnm", query.detail.receBnkCode));

            int ReceSameBnk = Integer.parseInt(query.detail.receSameBnk);
            switch (ReceSameBnk) {
                case 1:
//                    -质权人是否为中信银行标志 char(1) 0：是，1：不是 -->
                    //如果质权人账号是0，那么质权人账号是中信银行，反之，则不是
                    if("0".equals(query.detail.receAct)) {
                        tmpElemnt.addChild(new XElement("cobkIsCitic", "0"));
                    }else{
                        tmpElemnt.addChild(new XElement("cobkIsCitic", "1"));
                    }                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("cobkIsCitic", "1"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "质权人是否为中信银行标志错误";
                    Resp.writeDetail(respDetail);
                    continue;
            }

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB108BillPaySubmit D_B108(ReqB108BillPaySubmit query) throws Exception {
        RetAtsB108BillPaySubmit Resp = new RetAtsB108BillPaySubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB108BillPaySubmitDetail respDetail = new RetAtsB108BillPaySubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLTSFKSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            int ProPayType = Integer.parseInt(query.detail.proPayType);
            switch (ProPayType) {
                case 1:
                    tmpElemnt.addChild(new XElement("bussType", "01"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("bussType", "02"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "提示付款类型错误";
                    Resp.writeDetail(respDetail);
            }
            tmpElemnt.addChild(new XElement("overdueRsn", query.detail.overDueRea));
            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB109BillGuarSubmit D_B109(ReqB109BillGuarSubmit query) throws Exception {
        RetAtsB109BillGuarSubmit Resp = new RetAtsB109BillGuarSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB109BillGuarSubmitDetail respDetail = new RetAtsB109BillGuarSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBOZHSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            tmpElemnt.addChild(new XElement("warrtrName", query.detail.receName));
            tmpElemnt.addChild(new XElement("warrtrAccNo", query.detail.receAct));
            tmpElemnt.addChild(new XElement("warrtrBnm", query.detail.receBnkCode));

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB110BillRecoSubmit D_B110(ReqB110BillRecoSubmit query) throws Exception {
        RetAtsB110BillRecoSubmit Resp = new RetAtsB110BillRecoSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB110BillRecoSubmitDetail respDetail = new RetAtsB110BillRecoSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLZSTZSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            int RecourseType = Integer.parseInt(query.detail.recourseType);
            switch (RecourseType) {
                case 1:
                    tmpElemnt.addChild(new XElement("rcrsType", "RT00"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("rcrsType", "RT01"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "追索类型错误";
                    Resp.writeDetail(respDetail);
            }

            tmpElemnt.addChild(new XElement("rcrsAmt", query.detail.recourseAmt));
            tmpElemnt.addChild(new XElement("rcvgCode", query.detail.receCode));
            if(RecourseType ==2) {
                int RecourseCode = Integer.parseInt(query.detail.recourseCode);
                switch (RecourseCode) {
                    case 1:
                        tmpElemnt.addChild(new XElement("rcrsRsnCode", "RC00"));
                        break;
                    case 2:
                        tmpElemnt.addChild(new XElement("rcrsRsnCode", "RC01"));
                        break;
                    default:
                        if (query.detail.recourseType.equals("2")) {
                            respDetail.respCode = "-1";
                            respDetail.respInfo = "追索理由代码错误";
                            Resp.writeDetail(respDetail);
                            continue;
                        } else {
                            break;
                        }
                }
            }else{
                tmpElemnt.addChild(new XElement("rcrsRsnCode", ""));
            }
            tmpElemnt.addChild(new XElement("rcvgName", query.detail.receName));
            tmpElemnt.addChild(new XElement("rcvgAccNo", query.detail.receAct));
            tmpElemnt.addChild(new XElement("rcvgBnm", query.detail.receBnkCode));

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB111BillAgreeSubmit D_B111(ReqB111BillAgreeSubmit query) throws Exception {
        RetAtsB111BillAgreeSubmit Resp = new RetAtsB111BillAgreeSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB111BillAgreeSubmitDetail respDetail = new RetAtsB111BillAgreeSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLTYQCSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            tmpElemnt.addChild(new XElement("bussqNo", query.detail.busiNo));
            tmpElemnt.addChild(new XElement("agreeAmt", query.detail.agreeAmt));

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB112BillCancSubmit D_B112(ReqB112BillCancSubmit query) throws Exception {
        RetAtsB112BillCancSubmit Resp = new RetAtsB112BillCancSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB112BillCancSubmitDetail respDetail = new RetAtsB112BillCancSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBCMACX"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));

            String reqCode;
            int CancelType = Integer.parseInt(query.detail.cancelType);
            switch (CancelType) {
                case 1://承兑申请撤回
                    reqCode = "DLTSCDCX";//提示承兑撤销
                    break;
                case 2://提示收票申请撤回
                    reqCode = "DLTSSPCX";//提示收票撤销
                    break;
                case 3://背书转让申请撤回
                    reqCode = "DLBSZRCX";//背书转让撤销
                    break;
                case 4://贴现申请撤回
                    reqCode = "DLTIEXCX";//贴现撤销
                    break;
                case 5://质押申请撤回
                    reqCode = "DLZHYACX";//质押撤销
                    break;
                case 6://（逾期）提示付款撤回
                    reqCode = "DLTSFKCX";//提示付款撤销
                    break;
                case 7://出票保证申请撤回
                    reqCode = "DLBOZHCX";//保证撤销
                    break;
                case 8://承兑保证申请撤回
                    reqCode = "DLBOZHCX";//保证撤销
                    break;
                case 9://背书保证申请撤回
                    reqCode = "DLBOZHCX";//保证撤销
                    break;
                case 10://追索通知撤回
                    reqCode = "DLZSTZCX";//追索通知撤销
                    break;
                case 11://同意清偿撤回
                    reqCode = "DLTYQCCX";//同意清偿撤销
                    break;
                case 12://质押解除撤回
                    reqCode = "DLZYJCCX";//质押解除撤回
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "系统不支持该撤回类型。";
                    Resp.writeDetail(respDetail);
                    continue;
            }
            tmpElemnt.addChild(new XElement("reqCode", reqCode));
            tmpElemnt.addChild(new XElement("bussqNo", query.detail.busiNo));

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));

            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }

    public RetAtsB106BillDiscSubmit D_B106(ReqB106BillDiscSubmit query) throws Exception {
        RetAtsB106BillDiscSubmit Resp = new RetAtsB106BillDiscSubmit(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB106BillDiscSubmitDetail respDetail = new RetAtsB106BillDiscSubmitDetail();
            respDetail.reqSeqID = query.detail.reqSeqID;
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLTIEXSQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            int ReceSameBnk = Integer.parseInt(query.detail.receSameBnk);
            switch (ReceSameBnk) {
                case 1:
                    tmpElemnt.addChild(new XElement("dsbkIsCitic", "0"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("dsbkIsCitic", "1"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "贴入人是否为中信银行标志错误。";
                    Resp.writeDetail(respDetail);
                    continue;
            }

            tmpElemnt.addChild(new XElement("dsbkName", query.detail.receName));

            if (query.detail.receSameBnk.equals("1")) {
                tmpElemnt.addChild(new XElement("dsbkAccNo", "0"));
            } else {
                tmpElemnt.addChild(new XElement("dsbkAccNo", query.detail.receAct));
            }
            tmpElemnt.addChild(new XElement("dsbkBnm", query.detail.receBnkCode));
            int DiscType = Integer.parseInt(query.detail.discType);
            switch (DiscType) {
                case 1:
                    tmpElemnt.addChild(new XElement("dscntType", "RM00"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("dscntType", "RM01"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "贴现种类错误。";
                    Resp.writeDetail(respDetail);
                    continue;
            }

            if (!StringHelper.isNullOrEmpty(query.detail.repOpenDate)) {
                tmpElemnt.addChild(new XElement("rpdStartDate", TransDateFromATS(query.detail.repOpenDate)));
            }
            if (!StringHelper.isNullOrEmpty(query.detail.repDueDate)) {
                tmpElemnt.addChild(new XElement("rpdDueDate", TransDateFromATS(query.detail.repDueDate)));
            }
            tmpElemnt.addChild(new XElement("rpdRate", query.detail.repRate));
            tmpElemnt.addChild(new XElement("rpdAmt", query.detail.repAmt));
            tmpElemnt.addChild(new XElement("dscntRate", query.detail.discRate));
            tmpElemnt.addChild(new XElement("aoaiAccNo", query.detail.actedAct));
            tmpElemnt.addChild(new XElement("aoaiBnm", query.detail.actedBnkCode));

            int TransFlag = Integer.parseInt(query.detail.transFlag);
            switch (TransFlag) {
                case 1:
                    tmpElemnt.addChild(new XElement("endorseMk", "EM00"));
                    break;
                case 0:
                    tmpElemnt.addChild(new XElement("endorseMk", "EM01"));
                    break;
                default:
                    respDetail.respCode = "-1";
                    respDetail.respInfo = "转让标识错误。";
                    Resp.writeDetail(respDetail);
                    continue;
            }

            if(ReceSameBnk==1) {
                BigDecimal discAmt =getDiscAmt(query.detail);
                tmpElemnt.addChild(new XElement("realAmt", discAmt.setScale(2, BigDecimal.ROUND_HALF_UP).toString()));
            }
            tmpElemnt.addChild(new XElement("contractNo", query.detail.contractNo));
            tmpElemnt.addChild(new XElement("invoiceNo", query.detail.invoiceNo));

            tmpElemnt.addChild(new XElement("memo", query.detail.memo));
            tmpElemnt.addChild(new XElement("preFlg", "0"));
            tmpElemnt.addChild(new XElement("inteMthd", "02"));

            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    respDetail.respCode = "0";
                    respDetail.respInfo = tmpBkReader.getSimpleText("statusText");
                    respDetail.payInfoCode = tmpBkReader.getSimpleText("status");
                    respDetail.transState = tmpBkReader.getSimpleText("status");
                } else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                respDetail.respCode = "-1";
                respDetail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(respDetail);
        }
        Resp.writeAfter();
        return Resp;
    }
}
